24  Pixel size

(通过script获得)像素大小/pixel size

Published

January 17, 2026

1. 像素大小的定义(以显微镜为例)(1)

One way to think about this in microscopy is to consider the field of view of an image, i.e. the width and height of the area that has been imaged. We can divide the width and height in physical units (often µm) by the number of pixels along that dimension.

The result is that we have two value in µm/px, corresponding to the pixel width and pixel height. Usually these are the same.

2. 像素大小的意义(1)

The ‘pixel size’ is an idea that helps us translate measurements we make in images to the sizes and positions of things in real life.

Knowing the pixel size makes it possible to calibrate size measurements. For example, if we measure some structure horizontally in the image and find that it is 10 pixels in length, with a pixel size of 0.5µm, we can deduce that its actual length in reality is (approximately!) 10 × 0.5µm = 5µm.

3. 通过QuPath查看像素大小

3.1 通过QuPath软件界面

通过QuPath软件界面的image panel。

通过QuPath软件界面的image panel,可知该HE染色的组织切片图像的pixel width和pixel height都是0.2739 µm。

Pixel width和pixel height相同。

3.2 通过groovy script

// QuPath v0.6.0

// Get image name, pixel width, pixel height, and pixel type.
def imageName = getCurrentImageNameWithoutExtension()

def metaData = getCurrentServer().getMetadata()

def pixelWidth = metaData.getPixelWidthMicrons()
def pixelHeight = metaData.getPixelHeightMicrons()

// Print image name, pixel width, and pixel height.
println "Image name: ${imageName}"

println "Pixel width: ${pixelWidth}"
println "Pixel height: ${pixelHeight}"

println "Done!"

通过groovy script获得像素大小。

通过groovy script可知,该图像的pixel width为0.27385541963588983 µm,pixel height为0.27385493509814707 µm。

严格来讲,pixel width和pixel height不同。

如果通过groovy script将pixel size四舍五入呢?

// QuPath v0.6.0

// Get image name, pixel width, pixel height, and pixel type.
def imageName = getCurrentImageNameWithoutExtension()

def metaData = getCurrentServer().getMetadata()

def pixelWidth = metaData.getPixelWidthMicrons()
def pixelWidthRound = pixelWidth.round(4) // Round to 4 decimal places.

def pixelHeight = metaData.getPixelHeightMicrons()
def pixelHeightRound = pixelHeight.round(4)

// Print image name, pixel width, and pixel height.
println "Image name: ${imageName}"

println "Pixel width (rounded): ${pixelWidthRound}"
println "Pixel height (rounded): ${pixelHeightRound}"

println "Done!"

通过groovy script获得像素大小,并四舍五入到小数点后第4位。

这时候(即四舍五入到小数点后第4位)pixel width和pixel height都是0.2739 µm。Pixel width和pixel height又相同了。

给我买杯茶🍵

1.
Pete, Bankhead, Introduction to bioimage analysis (2022-2025). https://bioimagebook.github.io/chapters/1-concepts/5-pixel_size/pixel_size.html.